import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
    base: "/",
    mode: 'hash',
    routes: [
        // 首页
        {
            path: '/',
            name: 'Index',
            component: resolve => require(['@/pages/index/index'], resolve)
        },
        // 搜索商品
        {
            path: '/search',
            name: 'Search',
            component: resolve => require(['@/pages/search/search'], resolve)
        },
        // 搜索商品结果
        {
            path: '/searchResult',
            name: 'SearchResult',
            component: resolve => require(['@/pages/search/searchResult'], resolve)
        },
        // 秒杀
        {
            path: '/seckill',
            name: 'Seckill',
            component: resolve => require(['@/pages/index/seckill'], resolve)
        },
        // 店铺详情
        {
            path: '/storeDetail',
            name: 'StoreDetail',
            component: resolve => require(['@/pages/becomeStore/storeDetail'], resolve)
        },
        // 共享商品
        {
            path: '/classify',
            name: 'Classify',
            component: resolve => require(['@/pages/index/classify'], resolve)
        },
        // 商品详情
        {
            path: '/goodsDetail',
            name: 'GoodsDetail',
            component: resolve => require(['@/pages/index/goodsDetail'], resolve)
        },
        // 购物车
        {
            path: '/car',
            name: 'Car',
            component: resolve => require(['@/pages/index/car'], resolve)
        },
        // 我的
        {
            path: '/center',
            name: 'Center',
            component: resolve => require(['@/pages/user/center'], resolve)
        },
        // 会员码
        {
            path: '/inviteCode',
            name: 'InviteCode',
            component: resolve => require(['@/pages/user/inviteCode'], resolve)
        },
        // 注册
        {
            path: '/register',
            name: 'Register',
            component: resolve => require(['@/pages/set/register'], resolve)
        },
        // 登录
        {
            path: '/login',
            name: 'Login',
            component: resolve => require(['@/pages/set/login'], resolve)
        },
        // 老系统登录
        {
            path: '/oldUser',
            name: 'OldUser',
            component: resolve => require(['@/pages/set/oldUser'], resolve)
        },
        // 绑定手机号
        {
            path: '/bindtel',
            name: 'Bindtel',
            component: resolve => require(['@/pages/set/bindtel'], resolve)
        },
        // 绑定手机号
        {
            path: '/bindMobile',
            name: 'BindMobile',
            component: resolve => require(['@/pages/set/bindMobile'], resolve)
        },
        // 用户协议
        {
            path: '/treaty',
            name: 'Treaty',
            component: resolve => require(['@/pages/set/treaty'], resolve)
        },
        // 忘记密码
        {
            path: '/forgotpwd',
            name: 'Forgotpwd',
            component: resolve => require(['@/pages/set/forgotpwd'], resolve)
        },
        // 拼团订单
        {
            path: '/groupOrder',
            name: 'GroupOrder',
            component: resolve => require(['@/pages/orders/groupOrder'], resolve)
        },
        // 优惠券
        {
            path: '/coupons',
            name: 'Coupons',
            component: resolve => require(['@/pages/user/coupons'], resolve)
        },
        // 兑换优惠券
        {
            path: '/changeCode',
            name: 'ChangeCode',
            component: resolve => require(['@/pages/user/changeCode'], resolve)
        },
        // 领券中心
        {
            path: '/couponCenter',
            name: 'CouponCenter',
            component: resolve => require(['@/pages/user/couponCenter'], resolve),
        },
        // 优惠券使用记录
        {
            path: '/couponsDetail',
            name: 'CouponsDetail',
            component: resolve => require(['@/pages/user/couponsDetail'], resolve),
        },
        // 商品收藏
        {
            path: '/collect',
            name: 'Collect',
            component: resolve => require(['@/pages/user/collect'], resolve)
        },
        // 店铺收藏
        {
            path: '/collectStore',
            name: 'CollectStore',
            component: resolve => require(['@/pages/user/collectStore'], resolve)
        },
        // 收货地址
        {
            path: '/address',
            name: 'Address',
            component: resolve => require(['@/pages/address/address'], resolve)
        },
        // 添加、编辑收货地址
        {
            path: '/addressAdd',
            name: 'AddressAdd',
            component: resolve => require(['@/pages/address/addressAdd'], resolve)
        },
        // 意见反馈
        {
            path: '/feedback',
            name: 'Feedback',
            component: resolve => require(['@/pages/user/feedback'], resolve)
        },
        // 关于我们
        {
            path: '/aboutUs',
            name: 'AboutUs',
            component: resolve => require(['@/pages/user/aboutUs'], resolve)
        },
        // 设置
        {
            path: '/set',
            name: 'Set',
            component: resolve => require(['@/pages/set/set'], resolve)
        },
        // 设置支付密码
        {
            path: '/setPwd',
            name: 'SetPwd',
            component: resolve => require(['@/pages/set/setPwd'], resolve)
        },
        // 修改登录密码
        {
            path: '/changePwd',
            name: 'ChangePwd',
            component: resolve => require(['@/pages/set/changePwd'], resolve)
        },
        // 支付管理
        {
            path: '/payCharge',
            name: 'PayCharge',
            component: resolve => require(['@/pages/set/payCharge'], resolve)
        },
        // 修改支付密码
        {
            path: '/changePay',
            name: 'ChangePay',
            component: resolve => require(['@/pages/set/changePay'], resolve)
        },
        // 忘记支付密码
        {
            path: '/forgetPay',
            name: 'ForgetPay',
            component: resolve => require(['@/pages/set/forgetPay'], resolve)
        },
        // 确认订单
        {
            path: '/confirmOrder',
            name: 'ConfirmOrder',
            component: resolve => require(['@/pages/index/confirmOrder'], resolve)
        },
        // 确认订单
        {
            path: '/orderPay',
            name: 'OrderPay',
            component: resolve => require(['@/pages/index/orderPay'], resolve)
        },
        // 支付结果
        {
            path: '/payResult',
            name: 'PayResult',
            component: resolve => require(['@/pages/index/payResult'], resolve)
        },
        // 我的订单
        {
            path: '/myOrders',
            name: 'MyOrders',
            component: resolve => require(['@/pages/orders/myOrders'], resolve),
        },
        // 售后订单
        {
            path: '/afterOrder',
            name: 'afterOrder',
            component: resolve => require(['@/pages/orders/afterOrder'], resolve),
        },
        // 订单详情
        {
            path: '/orderDetail',
            name: 'OrderDetail',
            component: resolve => require(['@/pages/orders/orderDetail'], resolve),
        },
        // 拼团订单详情
        {
            path: '/groupOrderDetail',
            name: 'GroupOrderDetail',
            component: resolve => require(['@/pages/orders/groupOrderDetail'], resolve),
        },
        // 全部评论
        {
            path: '/evaluates',
            name: 'Evaluates',
            component: resolve => require(['@/pages/index/evaluates'], resolve),
        },
        // 升级商户
        {
            path: '/becomeStore',
            name: 'BecomeStore',
            component: resolve => require(['@/pages/becomeStore/becomeStore'], resolve),
        },
        // 升级商户结果
        {
            path: '/reqResult',
            name: 'ReqResult',
            component: resolve => require(['@/pages/becomeStore/reqResult'], resolve),
        },
        // 通知公告
        {
            path: '/announce',
            name: 'Announce',
            component: resolve => require(['@/pages/index/announce'], resolve),
        },
        // 通知公告详情
        {
            path: '/announceDetail',
            name: 'AnnounceDetail',
            component: resolve => require(['@/pages/index/announceDetail'], resolve),
        },
        // 我的伞下
        {
            path: '/distribution',
            name: 'Distribution',
            component: resolve => require(['@/pages/distribution/index'], resolve),
        },
        // 订单记录
        {
            path: '/orderHis',
            name: 'OrderHis',
            component: resolve => require(['@/pages/distribution/orderHis'], resolve),
        },
        // 伞下概况
        {
            path: '/teamDetail',
            name: 'TeamDetail',
            component: resolve => require(['@/pages/distribution/teamDetail'], resolve),
        },
        // 收益
        {
            path: '/earn',
            name: 'Earn',
            component: resolve => require(['@/pages/distribution/earn'], resolve),
        },
        // 我要提现
        {
            path: '/wantCash',
            name: 'WantCash',
            component: resolve => require(['@/pages/distribution/wantCash'], resolve),
        },
        // 提现
        {
            path: '/cash',
            name: 'Cash',
            component: resolve => require(['@/pages/distribution/cash'], resolve),
        },
        // 收益明细
        {
            path: '/earnDetail',
            name: 'EarnDetail',
            component: resolve => require(['@/pages/distribution/earnDetail'], resolve),
        },
        // 银行卡
        {
            path: '/bankCard',
            name: 'BankCard',
            component: resolve => require(['@/pages/distribution/bankCard'], resolve),
        },
        // 添加银行卡
        {
            path: '/bankCardAdd',
            name: 'BankCardAdd',
            component: resolve => require(['@/pages/distribution/bankCardAdd'], resolve),
        },
        // 邀请好友
        {
            path: '/invite',
            name: 'Invite',
            component: resolve => require(['@/pages/distribution/invite'], resolve),
        },
        // 邀请好友规则
        {
            path: '/rules',
            name: 'Rules',
            component: resolve => require(['@/pages/distribution/rules'], resolve),
        },
        // 售后订单详情
        {
            path: '/afterDetail',
            name: 'AfterDetail',
            component: resolve => require(['@/pages/orders/afterDetail'], resolve),
        },
        // 申请售后 已付款状态 单商品
        {
            path: '/reqAfter',
            name: 'ReqAfter',
            component: resolve => require(['@/pages/orders/reqAfter'], resolve),
        },
        // 选择服务类型
        {
            path: '/afterType',
            name: 'AfterType',
            component: resolve => require(['@/pages/orders/afterType'], resolve),
        },
        // 选择售后商品
        {
            path: '/afterGoods',
            name: 'AfterGoods',
            component: resolve => require(['@/pages/orders/afterGoods'], resolve),
        },
        // 填写单号
        {
            path: '/fillOrder',
            name: 'FillOrder',
            component: resolve => require(['@/pages/orders/fillOrder'], resolve),
        },
        // 选择物流公司
        {
            path: '/chooseLogistic',
            name: 'ChooseLogistic',
            component: resolve => require(['@/pages/orders/chooseLogistic'], resolve),
        },
        // 其他物流公司
        {
            path: '/otherLogistic',
            name: 'OtherLogistic',
            component: resolve => require(['@/pages/orders/otherLogistic'], resolve),
        },
        // 用户信息
        {
            path: '/userInfo',
            name: 'UserInfo',
            component: resolve => require(['@/pages/user/userInfo'], resolve),
        },
        // 评价
        {
            path: '/evaluate',
            name: 'Evaluate',
            component: resolve => require(['@/pages/orders/evaluate'], resolve),
        },
        // 拼团中心
        {
            path: '/group',
            name: 'Group',
            component: resolve => require(['@/pages/group/group'], resolve),
        },
        // 拼团详情
        {
            path: '/groupDetail',
            name: 'GroupDetail',
            component: resolve => require(['@/pages/group/groupDetail'], resolve),
        },
        // 分享进入
        {
            path: '/sharein',
            name: 'Sharein',
            component: resolve => require(['@/pages/group/sharein'], resolve),
        },
        // 更改昵称
        {
            path: '/changeName',
            name: 'ChangeName',
            component: resolve => require(['@/pages/user/changeName'], resolve),
        },
        // 查看物流
        {
            path: '/look',
            name: 'Look',
            component: resolve => require(['@/pages/orders/look'], resolve),
        },
        // 商品追溯
        {
            path: '/goodsTrace',
            name: 'GoodsTrace',
            component: resolve => require(['@/pages/index/goodsTrace'], resolve),
        },
        // 入驻协议
        {
            path: '/settled',
            name: 'Settled',
            component: resolve => require(['@/pages/user/settled'], resolve),
        },
        // 举报
        {
            path: '/report',
            name: 'Report',
            component: resolve => require(['@/pages/orders/report'], resolve),
        },
    ],
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            if (from.meta.keepAlive) {
                // 在触发路由切换时，如果当前页面需要缓存数据，那么在其路由的meta.savedPostion中保存当前页面的滚动位置数据
                from.meta.savedPosition = document.body.scrollTop || document.documentElement.scrollTop;
            }
            // 切换路由时，检测其meta.savedPosition, 如果有值则将其滚动到缓存位置       
            return { x: 0, y: to.meta.savedPosition || 0 }
        }
    }
})